//
//  PanicBuyTableViewCell.m
//  快圈
//
//  Created by ym on 16/9/12.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "PanicBuyTableViewCell.h"

@interface PanicBuyTableViewCell ()<UIScrollViewDelegate>
@property (nonatomic,strong)NSMutableArray *ImageDataArr;
@end

@implementation PanicBuyTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];

    UIView *defaltView = [[UIView alloc]init];
    defaltView = self.contentView;
    // 80
    self.TopScView.sd_layout.topEqualToView(defaltView).leftEqualToView(defaltView).rightEqualToView(defaltView).heightIs(210);
    
    self.Name.sd_layout.topSpaceToView(self.TopScView,10).leftSpaceToView(defaltView,15).heightIs(30);
    self.moneyPrice.sd_layout.leftEqualToView(self.Name).topSpaceToView(self.Name,12);
    self.SouBeiPrice.sd_layout.leftSpaceToView(self.moneyPrice,30).topEqualToView(self.moneyPrice).heightRatioToView(self.moneyPrice,1);
    self.pageControll.sd_layout.topSpaceToView(self.TopScView,-30).centerXIs(WIDTH/2 ).widthIs(100).heightIs(30);
    self.moneyPrice.textColor = TempGreen;
    self.SouBeiPrice.textColor = TempGreen;
    self.BuyBtn.sd_layout.rightSpaceToView(defaltView,25).topSpaceToView(self.TopScView,23).widthIs(100).heightIs(40);
    self.BuyBtn.backgroundColor = BackColour;
    self.BuyBtn.layer.masksToBounds = YES;
    self.BuyBtn.layer.cornerRadius  = 5;

//    [ self.BuyBtn.layer setBorderWidth:20];//设置边界的宽度
//    [ self.BuyBtn.layer setBorderColor:(__bridge CGColorRef _Nullable)([UIColor redColor])];
     self.BuyBtn.layer.borderColor = [TempGreen CGColor];
     self.BuyBtn.layer.borderWidth = 1.0f;
}

- (void)setModel:(panicBuyModel *)model{
    self.Name.text = model.name;
    self.moneyPrice.text = model.moneyPrice;
    self.SouBeiPrice.text = model.SouPrice;
    self.ImageDataArr = [NSMutableArray arrayWithArray:model.imageArr];
    self.TopScView.contentSize = CGSizeMake(WIDTH * self.ImageDataArr.count , 0);
    self.pageControll.numberOfPages = self.ImageDataArr.count;
    
    for (NSInteger i = 0 ; i < self.ImageDataArr.count; i ++) {
        UIImageView *a = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH,  self.TopScView.height)];
        [ self.TopScView addSubview:a];
        a.image = self.ImageDataArr[i];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    if (scrollView.tag == 2001) {
        if (scrollView.contentOffset.x / WIDTH == self.ImageDataArr.count) {
            scrollView.contentOffset = CGPointZero;
        }
        // 设置当前页码
        UIPageControl *pc = (UIPageControl *)[self.contentView viewWithTag:2000];
        pc.currentPage = scrollView.contentOffset.x / WIDTH;
    }
    
}

@end
